home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '88 / Other stuff / CLIP stuff / CLIP sources / mxmul.c < prev   
Encoding:
C/C++ Source or Header  |  1986-04-28  |  3.2 KB  |  91 lines  |  [TEXT/FstE]

  1. /*  Copyright (c)   Mar, 1986   UMMC.  All rights reserved
  2.  
  3. Filename:       mxmul.c
  4.  
  5. Abstract:       determines which header files must be included with each clip demo module
  6.  
  7. Environment:    UM/CLIP
  8.  
  9. Revision History:
  10.     Rev #     Date     Auth     Reason
  11.     -----   ---------  ----     ----------------------------------
  12.      0.0    12-mar-86   js      original implementation
  13.      0.1    28-apr-86   js      converted to double precision
  14. =========================================================================================
  15. NAME:
  16.  
  17.     mxmul - matrix multiplication
  18.  
  19. SYNOPSIS:
  20.  
  21.     ERRCODE mxmul(mx1, r1, c1, mx2, r2, c2, mxout)
  22.     
  23.         DOUBLE      *mx1;           pointer to array containing input matrix 1
  24.         INT         r1;             # of rows in input matrix 1
  25.         INT         c1;             # of collumns in input matrix 1
  26.         DOUBLE      *mx2;           pointer to array containing input matrix 2
  27.         INT         r2;             # of rows in input matrix 2
  28.         INT         c2;             # of collumns in input matrix 2
  29.         DOUBLE      *mxout;         pointer to array for output matrix
  30.  
  31. MODIFIED ARGUMENTS:
  32.  
  33.     none
  34.     
  35. FUNCTION:
  36.  
  37.     This subroutine performs a standard matrix multiplication of mx1 and mx2 yielding the output
  38.     matrix mxout.  The formula for any given element of mxout, result(i,j) is given by:
  39.     
  40.             result(i,j) = mx1(i,1) x mx2(1,j) + mx1(i,2) x mx2(2,j) + ......
  41.             
  42. PROGRAMMING NOTES:
  43.  
  44.     Since the arrays are passed as pointers, mxout must have enough space to store the entire
  45.     result or memory will be inadvertently over-written.  The output matrix will have the dimensions:
  46.     
  47.         rowsout = r1        colsout = c2
  48.  
  49. EXAMPLES:
  50.  
  51. =========================================================================*/
  52.  
  53. #include        "clipinclude.h"
  54.  
  55.     ERRCODE mxmul(mx1, r1, c1, mx2, r2, c2, mxout)
  56.         
  57.     DOUBLE      *mx1;           /*  pointer to array containing input matrix 1 */
  58.     INT         r1;             /* # of rows in input matrix 1 */
  59.     INT         c1;             /* # of columns in input matrix 1 */
  60.     DOUBLE      *mx2;           /* pointer to array containing input matrix 2 */
  61.     INT         r2;             /* # of rows in input matrix 2 */
  62.     INT         c2;             /* # of columns in input matrix 2 */
  63.     DOUBLE      *mxout;         /* pointer to array for output matrix */
  64.     
  65.     {
  66.     
  67.     INT         i;                  /* index for inner loop */
  68.     INT         rout, cout, index;  /* indices into mxout */
  69.     ERRCODE     erret = OK;         /* error code (init to OK) */
  70.     
  71.     
  72.     if (c1 != r2)                         /* check for matrix size mis-match */
  73.         erret = ERMXSZ;
  74.     else {
  75.         for (rout = 0; rout < r1; rout++) {                      /* for all output rows */
  76.             for (cout = 0; cout < c2; cout++) {              /* for all output collumns */
  77.                 
  78.                 index = (rout * c2) + cout;
  79.                 mxout[index] = 0;
  80.                 
  81.                 for (i = 0; i < c1; i++)          /* loop through appropriate values... */
  82.                     mxout[index] += (mx1[(rout * c1) + i] * mx2[(i * c2) + cout]);
  83.             }
  84.         }
  85.     }
  86.  
  87. /* all done */
  88.  
  89.     return (erret);
  90.     
  91. }